package com.zlj.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zlj.dao.BookDao;

import cn.itcast.servlet.BaseServlet;

/**
 * 页面静态化(图书管理小项目)
 * 
 * 页面静态化之如果文件存在直接重定向到html,如果不存在则生成html页面
 * 
 * @author bashen
 *
 */
@WebServlet("/BookServlet")
public class BookServlet extends BaseServlet {

	private BookDao bookDao = new BookDao();

	public String findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("bookList", bookDao.findAll());
		return "/show.jsp";
	}
	
	public String findByCategory(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    String value = request.getParameter("category");
	    int category = Integer.parseInt(value);
	    request.setAttribute("bookList", bookDao.findByCategory(category));
		return "/show.jsp";
	}
}
